//
//  ViewController.m
//  Etwo
//
//  Created by 林浩翔 on 16/6/16.
//  Copyright © 2016年 林浩翔. All rights reserved.
//

#import "ViewController.h"
#import "LHXTransferViewController.h"
#import "LHXTabBarViewController.h"
#import "LHXMainPresentController.h"
#import "LHXMainAnimationController.h"



@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIViewControllerTransitioningDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    bgImageView.image = [UIImage imageNamed:@"login_register_background"];
    
    [self.view addSubview:bgImageView];
    
    [self setButton];


    
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)setButton{
    LHXbutton *MainBtn = [LHXbutton btn];
    MainBtn.frame = CGRectMake(0, 0, 80, 80);



    [MainBtn setImage:[UIImage imageNamed:@"tabbar_compose_wbcamera"] forState:UIControlStateNormal];
    MainBtn.center = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height * 0.8);
    [MainBtn addTarget:self action:@selector(mainBtn:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:MainBtn];
}

//状态栏设为白色
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
};


- (void)mainBtn:(LHXbutton *)btn{

  
            
    UIImagePickerController *pickVC = [[UIImagePickerController alloc] init];
    //设置照片来源
    pickVC.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    //只要实现代理方法,必须得要手去关闭控制器
    pickVC.delegate = self;
    //跳转到系统相册控制器
    if ([LHXchoose shareChoose].chooseImage == nil) {
        [self presentViewController:pickVC animated:YES completion:nil];
    }else{
        LHXTransferViewController *transferVC = [[LHXTransferViewController alloc]init];
        
        transferVC.transitioningDelegate = self;
        transferVC.modalPresentationStyle = UIModalPresentationCustom;
        
        [self presentViewController:transferVC animated:YES completion:nil];
                
    }

    
}

//当选择照片完毕时调用
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    //获取点中选取的照片,用UIimage保存
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    //将获取到的图片用于别的地方
    LHXTransferViewController *transferVC = [[LHXTransferViewController alloc]init];
    
    [LHXchoose shareChoose].chooseImage = image;
    
    //手动关闭控制器
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    transferVC.transitioningDelegate = self;
    
    transferVC.modalPresentationStyle = UIModalPresentationCustom;
    
    [self presentViewController:transferVC animated:YES completion:nil];
    
}


#pragma mark --控制转场
//用来告诉系统谁来负责进行转场弹出控制器
- (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{
    
    
    return [[LHXMainPresentController alloc]initWithPresentedViewController:presented presentingViewController:presenting];
}


//用来告诉系统谁来负责弹出时候的动画
//当弹出控制器的时候调用
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    //1.创建自定义的对象
    LHXMainAnimationController *showDelegate = [[LHXMainAnimationController alloc]init];
    showDelegate.presented = YES;
    return showDelegate;
}
//用来告诉系统谁来负责销毁控制器时候的动画
//当销毁控制器的时候调用
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    LHXMainAnimationController *showDelegate = [[LHXMainAnimationController alloc]init];
    showDelegate.presented = NO;
    return showDelegate;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
